import 'package:flutter/material.dart';
import 'package:yp/helper.dart';
import 'package:get/get.dart';

import 'logic.dart';
import 'state.dart';

class SelectInvoiceHeadPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _SelectInvoiceHeadPage();
  }
}

class _SelectInvoiceHeadPage extends State<SelectInvoiceHeadPage> {
  final SelectInvoiceHeadLogic logic = Get.put(SelectInvoiceHeadLogic());
  final SelectInvoiceHeadState state = Get.find<SelectInvoiceHeadLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: setWidth(1),
        backgroundColor: Colors.white,
        title: Text(
          '选择发票抬头',
          style: TextStyle(
            color: Colors.black,
            fontSize: 17,
            fontWeight: FontWeight.bold,
          ),
        ),
        iconTheme: IconThemeData(
          color: Colors.black,
        ),
      ),
      body: GetBuilder<SelectInvoiceHeadLogic>(
        builder: (logic) {
          return Container(
            color: Color(0xfff5f5f5),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: ListView.separated(
                    scrollDirection: Axis.vertical,
                    padding: EdgeInsets.only(
                      left: setWidth(20),
                      top: setWidth(40),
                      right: setWidth(20),
                    ),
                    itemBuilder: (context, index) {
                      return Container(
                        height: 100,
                        decoration: BoxDecoration(
                          color: Colors.white.withOpacity(state.chooseIndex == index ? 0.7 : 1),
                          borderRadius: BorderRadius.circular(setWidth(10)),
                        ),
                        padding: EdgeInsets.only(
                          left: setWidth(28),
                          right: setWidth(22),
                        ),
                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Icon(
                              Icons.check,
                              color: Color(0xff50638e),
                              size: setWidth(32),
                            ),
                            SizedBox(width: setWidth(24)),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Text(
                                    '广州腾讯科技有限公司',
                                    style: TextStyle(
                                      color: Color(0xff3f3f3f).withOpacity(state.chooseIndex == index ? 0.7 : 1),
                                      fontSize: 17,
                                      fontWeight: FontWeight.bold,
                                    ),
                                  ),
                                  SizedBox(height: setWidth(6)),
                                  Text(
                                    '单位',
                                    style: TextStyle(
                                      color: Color(0xff717171).withOpacity(state.chooseIndex == index ? 0.7 : 1),
                                      fontSize: 14,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Container(
                              width: setWidth(120),
                              alignment: Alignment.centerRight,
                              child: index % 2 == 0 ? Text(
                                '已导入',
                                style: TextStyle(
                                  color: Color(0xff7D7D7D).withOpacity(state.chooseIndex == index ? 0.7 : 1),
                                  fontSize: 14,
                                ),
                              ) : Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: [
                                  Icon(
                                    Icons.error_outline,
                                    color: Color(0xff50638e),
                                    size: setWidth(34),
                                  ),
                                  SizedBox(width: setWidth(12)),
                                ],
                              ),
                            ),
                          ],
                        ),
                      );
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return SizedBox(
                        height: setWidth(20),
                      );
                    },
                    itemCount: 4,
                  ),
                ),
                InkWell(
                  onTap: () {
                    print('一键导入 点击事件！！！');
                  },
                  child: Container(
                    height: setWidth(96),
                    color: Color(0xffea5504),
                    alignment: Alignment.center,
                    child: Text(
                      '一键导入(2)',
                      style: TextStyle(
                        color: Colors.white,
                        fontSize: 17,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}